package com.ks.config;

import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.http.HttpHost;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * ES配置类
 *
 * @author KingAusten
 * @date 2022/08/17 16:59:28
 */
@Configuration
@EqualsAndHashCode(callSuper = false)
@Data
public class EsConfig{

    @Value("${elasticsearch.host}")
    private String host;

    @Value("${elasticsearch.port}")
    private int port;

    @Bean(destroyMethod = "close")
    public RestHighLevelClient restHighLevelClient(){

        return new RestHighLevelClient(RestClient.builder(new HttpHost(host,port,"http")));
    }

}
